package modelo;


import java.sql.*;

public class Conexion {
	static String bd = "miBD";
	static String login = "root";
	static String password = "";
	static String url = "jdbc:mysql://localhost/"+bd;
	
	Connection conn = null;
	
	/** Constructor de DbConection*/
	
	public Conexion() {
		try{
			//obtenemos el driver para mysql
			Class.forName("com.mysql.jdbc.Driver");
			//obtenemos la conexion
			conn = DriverManager.getConnection(url,login,password);
					
			if(conn!=null){
				System.out.println("Conexion a base de datos "+bd+" OK");
			}
		}
		catch(SQLException e){
			System.out.println(e);
		}catch(ClassNotFoundException e){
			System.out.println(e);
		}catch(Exception e){
			System.out.println(e);
		}
	}
	
	/*permite retornar la conexion*/
	public Connection getConnection() {
		return conn;
	}
	
	public void desconectar(){
		conn = null;
	}
	
	public static void main (String[] args){
		Conexion cn = new Conexion();
		cn.getConnection();
	}
}
